# -*- encoding: utf-8 -*-
def bubble_sort(collection):
    """冒泡排序
    input： list
    return: list
    Examples:
    >>> bubble_sort([0, 5, 3, 2, 2])
    [0, 2, 2, 3, 5]
    >>> bubble_sort([])
    []
    >>> bubble_sort([-2, -5, -45])
    [-45, -5, -2]

    >>> bubble_sort([-23,0,6,-4,34])
    [-23, -4, 0, 6, 34]
    """
    length = len(collection)
    for i in range(length - 1):
        swapped = False
        for j in range(length - 1 - i):
            if collection[j] > collection[j + 1]:
                swapped = True
                collection[j], collection[j + 1] = collection[j + 1], collection[j]
        if not swapped:
            # 经过第一轮冒泡，没有发生位置变化，说明本身已经是有序的了，所以退出循环
            break
    return collection


if __name__ == '__main__':
    user_input = input('Enter numbers separated by a comma:').strip()  # 9,8,7,6,4,5,3,2,1
    unsorted = [int(item) for item in user_input.split(',')]
    print(*bubble_sort(unsorted), sep=',')
